package com.valhalla.blogs.service.impl;

import com.valhalla.blogs.dao.UserMapper;
import com.valhalla.blogs.entity.User;
import com.valhalla.blogs.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

//    public User selectByPrimaryKey(Long id){
//        return userMapper.selectByPrimaryKey(id);
//    };

    @Override
    @Transactional
    public int regist(User user) {
        return userMapper.insert(user);
    }


//    public User login(String name, String password) {
//        User user = new User();
//        user.setEmail(name);
//        user.setPassword(password);
//        return userMapper.selectOne(user);
//        //return userMapper.findUserByNameAndPwd( name,password );
//    }

    public User findByEmail(String email) {
        User user = new User();
        user.setEmail(email);
        return userMapper.selectOne(user);
        // return userMapper.findByEmail(email);
    }

    @Override
    public void deleteByEmail(String email) {

    }

    //整个类更新需要在实体类中表示主键@Id 从而根据主键更新
    @Override
    public void update(User userTrue) {
    }

    public User findByPhone(String phone) {
        User user = new User();
        user.setPhone(phone);
        return userMapper.selectOne(user);
    }

//    public User findById(Long id) {
//        User user = new User();
//        user.setId(id);
//        return userMapper.selectOne(user);
//    }
//
//    public User findByEmailActive(String email) {
//        User user = new User();
//        user.setEmail(email);
//        return userMapper.selectOne(user);
//        // return userMapper.findByEmail(email);
//    }
//
//    public User findById(String id) {
//        User user = new User();
//        Long uid = Long.parseLong(id);
//        user.setId(uid);
//        return userMapper.selectOne(user);
//    }
//
//    public User findById(long id) {
//        User user = new User();
//        user.setId(id);
//        return userMapper.selectOne(user);
//    }
//
//    public void deleteByEmailAndFalse(String email) {
//        User user = new User();
//        user.setEmail(email);
//        userMapper.delete(user);
//    }


}
